home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10068 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  46 lines

  1. Path: hal.COM!spike
  2. From: spike@hal.com (Spike White)
  3. Newsgroups: comp.lang.c++
  4. Subject: Using typedefs in templates (not a FAQ)
  5. Date: 5 Mar 1996 22:58:46 GMT
  6. Organization: HAL Computer Systems, Inc.
  7. Message-ID: <4higv6$7ih@news.hal.com>
  8. NNTP-Posting-Host: zarathustra.hal.com
  9. X-Newsreader: TIN [version 1.2 PL2]
  10.  
  11. I want to typedef a new type based on the types of the formal template
  12. parameter list.  Is that possible?
  13.  
  14. Something like:
  15.  
  16. template <class KEY, class NODEDATA>
  17. class Tree {
  18. public:
  19.        typedef int (*pfid)(NODEDATA);
  20.        typedef int (*pfi2c)(const KEY, const NODEDATA);
  21. ...
  22.        pfi2c pfi_compare;  // my compare function
  23. ...
  24.        int trav(pfid);     // perform the function on each node
  25. ...
  26. }
  27.  
  28. Obviously, I could "uglify" my header file and C file by replacing the 
  29. typedefs w/ the literal expansion, but I'd rather not do that.  And I
  30. can't figure out a macro that would work.
  31.  
  32. I've also considered passing these new types when instantiating, as
  33. the 3rd and 4th formal parameters.  How would that be done?  Would it be
  34. something like:
  35.  
  36. template <class KEY, class NODEDATA, class int (*pfid)(NODEDATA), ... >
  37. {
  38. ...
  39. }
  40.  
  41. --
  42. Spike White          | spike@hal.com               | Biker Nerds
  43. HaL Software Systems | '87 BMW K75S, DoD #1347     |  From  HaL
  44. Austin, TX           |  http://www.halsoft.com/users/spike/index.html 
  45. Disclaimer:  HaL, want me to speak for you?  No, Dave... 
  46.